// pages/member/IntegralActivity/IntegralActivity.js
var app = getApp();
const skinBehavior = require('../../../utils/themeSkin/skinBehavior');
Page({
  behaviors: [skinBehavior],
  /**
	 * 页面的初始数据
	 */
  data: {
    activity_used: 0.00,
    activity_total: 0,
    activity_point: 0.00,
    activity_stock: 0.00,
    dataList: [],
    total_page: 0,
    integral: '',
  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  onLoad: function(options) {

  },

  /**
	 * 生命周期函数--监听页面初次渲染完成
	 */
  onReady: function() {

  },

  /**
	 * 生命周期函数--监听页面显示
	 */
  onShow: function() {
    this._initData();
    this._getData();
    try {
      const value = wx.getStorageSync('integral');
      if (value) {
        this.setData({
          integral: value
        });
        if (this.data.integral) {
          wx.setNavigationBarTitle({
            title: this.data.integral + '活动'
          });
        }
        // Do something with return value
      }
    } catch (e) {
      // Do something when catch error
    }
  },

  /**
	 * 生命周期函数--监听页面隐藏
	 */
  onHide: function() {

  },

  /**
	 * 生命周期函数--监听页面卸载
	 */
  onUnload: function() {

  },

  /**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
  onPullDownRefresh: function() {

  },

  /**
	 * 页面上拉触底事件的处理函数
	 */
  onReachBottom: function() {

  },

  /**
	 * 用户点击右上角分享
	 */
  onShareAppMessage: function() {

  },
  _initData() {
    this.setData({
      activity_used: 0.00,
      activity_total: 0,
      activity_point: 0.00,
      activity_stock: 0.00,
      dataList: [],
      total_page: 0,
      integral: '',
    });
  },
  _getData() {
    let that = this;
    let urlStr = app.getNetAddresss("plugin.point-activity.Frontend.Controllers.page.index");
    app._postNetWork({
      url: urlStr,
      showToastIn: false,
      data: this.data.form,
      success: function(resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          let activityDate = res.data;
          that.setData({
            activity_used: activityDate.activity_used,
            activity_total: activityDate.activity_total,
            activity_point: activityDate.activity_point,
            activity_stock: activityDate.activity_stock,
            total_page: activityDate.records.last_page ? activityDate.records.last_page : '',
            latest_record:activityDate.latest_record,
          });
          if (!that.data.total_page) {
            that.setData({
              total_page: 0
            });
          }
          that.setData({
            dataList: activityDate.records.data ? activityDate.records.data : []
          });
          wx.setNavigationBarColor({
            frontColor: '#ffffff',
            backgroundColor: that.data.themeBaseColor,
            animation: {
              duration: 400,
              timingFunc: 'easeIn'
            }
          });
        } else {
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 1500
          });
        }

      },
      fail: function(res) {}
    });
  },
  //创建活动
  toIntegralGeneralization() {
    //IntegralGeneralization
    wx.navigateTo({
      url: '/packageB/member/IntegralGeneralization/IntegralGeneralization'
    });
  },
  //领取记录
  goGetRecord() {
    wx.navigateTo({
      url: '/packageB/member/IntegralGetRecord/IntegralGetRecord'
    });
  },
  //明细赠送记录
  toIntegralRecord(e) {
    let activity_id = e.currentTarget.dataset.activityid;
    wx.navigateTo({
      url: '/packageB/member/IntegralRecord/IntegralRecord?activity_id=' + activity_id
    });
  },
  //分享页面
  toIntegralPresent(e) {
    let activity_id = e.currentTarget.dataset.activityid;
    wx.navigateTo({
      url: '/packageB/member/IntegralPresent/IntegralPresent?activity_id=' + activity_id
    });
  },

});
